package database;

import java.util.HashMap;



/**
 * @author aioros
 * 
 * Package informations
 */
public class Package {
	
	/*-------------------- Fields ------------------------*/
	
	/** package id */
	private String pkgid;
	
	/** package name */
	private String name;
	
	/** package website */
	private String website;
	
	/** package responsible user */
	private String respusr;
	
	/** package licence */
	private String licence;
	
	/** package category */
	private String category;
	
	/** package short description */
	private String shortdesc;
	
	/** package creation date */
	private String creationdate;
	
	/** package last update */
	private String lastupdate;
	
	/** 
	 * package status 
	 * -> active
	 * -> deprecated
	 * -> deleted
	 */
	private String status;
	
	/**
	 * branchs list
	 */
	private HashMap<String,Branch> branches = new HashMap<String,Branch>();
	
	
	/*-------------------- Constructor ------------------------*/
	
	/**
	 * Build a packages
	 */
	public Package(){
		
	}

	
	/*-------------------- Methodes ------------------------*/

	public HashMap<String,Branch> getBranches() {
		return branches;
	}


	public void setBranchs(HashMap<String,Branch> branches) {
		this.branches = branches;
	}


	public String getCategory() {
		return category;
	}


	public void setCategory(String category) {
		this.category = category;
	}


	public String getCreationdate() {
		return creationdate;
	}


	public void setCreationdate(String creationdate) {
		this.creationdate = creationdate;
	}


	public String getLastupdate() {
		return lastupdate;
	}


	public void setLastupdate(String lastupdate) {
		this.lastupdate = lastupdate;
	}


	public String getLicence() {
		return licence;
	}


	public void setLicence(String licence) {
		this.licence = licence;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public String getPkgid() {
		return pkgid;
	}


	public void setPkgid(String pkgid) {
		this.pkgid = pkgid;
	}


	public String getRespusr() {
		return respusr;
	}


	public void setRespusr(String respusr) {
		this.respusr = respusr;
	}


	public String getShortdesc() {
		return shortdesc;
	}


	public void setShortdesc(String shortdesc) {
		this.shortdesc = shortdesc;
	}


	public String getStatus() {
		return status;
	}


	public void setStatus(String status) {
		this.status = status;
	}


	public String getWebsite() {
		return website;
	}


	public void setWebsite(String website) {
		this.website = website;
	}
	
	
	public String toString(){
	
	
		String spackage = " \n";
		
		spackage += "---------- pkgid :" + pkgid + "  name : " + name + " ----------------- \n \n";
	
		spackage += "	- website : " + website + "\n";
	
		spackage += "	- respusr : " + respusr + "\n";
		
		spackage += "	- licence : " + licence + "\n";
	
		spackage += "	- category : " + category + "\n";
		
		spackage += "	- shortdesc : " + shortdesc + "\n";
		
		spackage += "	- creationdate : " + creationdate + "\n";
		
		spackage += "	- lastupdate : " + lastupdate + "\n";
	
		spackage += "		- status : " + status + " \n";
		
			
		
		for (Branch branch : branches.values()){
			
			spackage += branch + "\n";
		}
	
		return spackage;
	}
	
	
	public int getBranchesCount(){
		return branches.size();
	}
	
	
	
	public String getDescriptionHTML(String branchid, String releaseid){
		
		String desc = "<html>";
		
		desc += "<h1>" + this.getName() + " </h1>";
		desc += this.getShortdesc() + "<br></br>";
		desc += "<hr></hr>";
		desc += "Version : <i>" + this.getBranches().get(branchid).getReleases().get(releaseid).getVersion() + "</i><br></br>";
		desc += "Website : <i>" + this.getWebsite() + "</i><br></br>";
		desc += "Licences : <i>" + this.getLicence() + "</i><br></br>";
		desc += "Last update : <i>" + this.getBranches().get(branchid).getReleases().get(releaseid).getLastupdate() + "</i><br></br> <br></br>";
		
		desc += "Description : <br></br>";
		desc += "<i>" + this.getBranches().get(branchid).getDescription() + "</i><br></br><br></br>";

		desc += "Release note : <br></br>";
		desc += "<i>" + this.getBranches().get(branchid).getReleases().get(releaseid).getReleasenote() + "</i>";
		
		desc += "</html>";
		
		return desc;
	}
}
